import React from 'react';
import {findDOMNode} from "react-dom";
import Message from '../components/message'
import Dialog from '../components/dialog'
import styles from './index/styles/app'
import gcss from './gobal'
import {State} from 'react-router'
import cx from 'classnames'
import ErrorHandlerActions from './index/actions/error'
import ErrorHandlerStore from './index/stores/error'
import ErrorPage from './pages/components/500'
import NotFoundPage from './pages/components/404'
import {saveDataToLocal} from './index/services/authentication'
import {PathRess} from '../constants/pathname'

export default React.createClass({

    getInitialState: function() {
        return ErrorHandlerStore.getState();
    },

    componentDidMount: function() {
        ErrorHandlerStore.listen(this.onChange);

    },

    componentWillUnmount: function() {
        ErrorHandlerStore.unlisten(this.onChange);
    },

    onChange: function(state){
        this.setState(state);
    },

    render: function(){
    	
    	 let tilte,
    	 	 conHt =  window.innerHeight,
    	 	 errTmp,
    	 	 pName = this.props.location.pathname;
    	 	 
    	 	 tilte = PathRess[pName];
    	 	 
    	 	if (!tilte) {
    	 		for(let i in PathRess){
    	 			if (pName.indexOf(i)>-1) {
    	 				tilte = PathRess[i];
    	 				break;
    	 			}
    	 		}
    	 	}
    	 	 tilte= tilte?tilte:'测试';
    		 document.title = tilte;

        const content = (() => {
            if(this.state.err){
                if(this.state.err === 404){
                	errTmp = <NotFoundPage />;
                }else{
                	errTmp = <ErrorPage />;
                }
                return (
                	 <div style={{minHeight:conHt }}>
                   		 {errTmp}
               		 </div>
                );
            }
            return (
                <div className="amount-content" ref="app" style={{minHeight:conHt }}>
                    {this.props.children}
                </div>
            );
        })()
        return (
            <div className="pcRoot">
                {content}
                <Message />
          
            </div>
        );
    }
})
